package views;
import controller.DecreateController;
import controller.UserController;
import entity.Decreate;
import entity.User;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class DecreateView {
    DecreateController DecreateController=new DecreateController();
    UserController userController=new UserController();
    BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in));
    public boolean insertDecreateView(){
        try{
            System.out.println("——————————欢迎进入用户装扮添加界面——————————");
            System.out.println("请输入想要添加装扮的用户id");
            String id=bufferedReader.readLine();
            System.out.println("请输入密保答案");
            String answer= bufferedReader.readLine();
            User user= userController.seekUserById(Integer.parseInt(id));
            if (user.getAnswer().equals(answer)){
                System.out.println("请输入想要添加的气泡名称:");
                String bubble=bufferedReader.readLine();
                System.out.println("请输入想要添加的主题名称:");
                String theme=bufferedReader.readLine();
                System.out.println("请输入想要添加的背景名称:");
                String background=bufferedReader.readLine();
                System.out.println("请输入想要添加的挂件名称:");
                String pendant=bufferedReader.readLine();
                Decreate decreate1=new Decreate(Integer.parseInt(id),bubble,theme,background,pendant);
                System.out.println(decreate1);
                return DecreateController.insertDecreateController(decreate1);
            }
        }
        catch(IOException e){
            System.out.println("io异常,添加失败");
            return false;
        }
        return false;
    }
    /*
    删除操作
     */
    public boolean deleteDecreateView(){
        try{
            System.out.println("————————欢迎进入用户装扮删除界面————————");
            System.out.println("请输入你想要删除装扮的用户的id");
            String id=bufferedReader.readLine();
            System.out.println("请输入你想要删除装扮的主题");
            String theme=bufferedReader.readLine();
            System.out.println("请输入密保答案");
            String answer=bufferedReader.readLine();
            User user=userController.seekUserById(Integer.parseInt(id));
            if(user.getAnswer().equals(answer)){
                return DecreateController.deleteDecreateByDecreateThemeController(Integer.parseInt(id),theme);
            }
        }
        catch(IOException e){
            System.out.println("io异常，删除失败!");
            return false;
        }
        return false;
    }
    /*
    更改用户装扮
     */
    public boolean changeDecreateView(){
        try{
            System.out.println("————————欢迎进入装扮更改界面————————");
            System.out.println("请输入想要更改的装扮的用户的id");
            String id=bufferedReader.readLine();
            System.out.println("请输入想要更改的装扮的装扮主题");
            String theme=bufferedReader.readLine();
            System.out.println("请输入密保答案");
            String answer=bufferedReader.readLine();
            System.out.println("请输入想要更改的装扮的装扮气泡");
            String bubble=bufferedReader.readLine();
            System.out.println("请输入想要更改的装扮的装扮主题");
            String theme1=bufferedReader.readLine();
            System.out.println("请输入想要更改的装扮的装扮背景");
            String background=bufferedReader.readLine();
            System.out.println("请输入需要更改的装扮的头像挂件");
            String pendant=bufferedReader.readLine();
            Decreate decreate=new Decreate(theme,answer,bubble,theme1,background,pendant);
            User user=userController.seekUserById(Integer.parseInt(id));
            if(user.getAnswer().equals(answer)){
                return DecreateController.changeDecreateByIdService(Integer.parseInt(id),theme,decreate);
            }
        }
        catch(IOException e){
            System.out.println("io异常,更改用户装扮失败!");
            return false;
        }
        return false;
    }
    /*
    装扮查询界面
     */
    public void seekDecreateView(){
        try{
            System.out.println("————————欢迎进入装扮查询界面————————");
            System.out.println("1.查询所有用户的装扮,2.查询指定用户id的装扮");
            switch (Integer.parseInt(bufferedReader.readLine())){
                case 1:
                    System.out.println("请输入用户id");
                    String id1=bufferedReader.readLine();
                    User user=userController.seekUserById(Integer.parseInt(id1));
                    if(user.getCall()==2){
                        System.out.println(DecreateController.seekAllDecreateService());
                    }
                    else{
                        System.out.println("抱歉,您没有访问权限!");
                    }
                    break;
                    case 2:
                        System.out.println("请输入你想要查询的id");
                        String id=bufferedReader.readLine();
                        System.out.println("请输入密保答案");
                        String answer=bufferedReader.readLine();
                        User user1=userController.seekUserById(Integer.parseInt(id));
                        if(user1.getAnswer().equals(answer)){
                            System.out.println(DecreateController.seekDecreateByIdController(Integer.parseInt(id)));
                        }
                        else{
                            System.out.println("密保答案错误,查询失败!");
                        }
                        break;
                default:
                    System.out.println("输入内容不符合要求,查询失败!");
                    break;
            }
        }
        catch(IOException e){
            System.out.println("io异常,查询失败!");
        }
    }
}
